'; window.popUpWin.document.write(zhtm); window.popUpWin.document.close(); // Johnny Jackson 4/28/98 } //--> Inside AutoCAD 14 -- Ch 14 -- T


Inside AutoCAD 14

Previous chapterNext chapterContents


- 14 -

Querying Objects


by Bill Burchard

To use the power of AutoCAD, you must be able to extract information from AutoCAD objects. When an object is created, AutoCAD does more than just draw the object on the computer screen. It creates a list of object data and stores this data in the drawing's database. This data includes not only the layer, color, and linetype of an object, but also the X,Y,Z coordinate values of an object's critical elements, such as the center of a circle, or the endpoint of a line. The data can include the names of blocks, as well as their X,Y,Z scale and rotation angles. Information about block attributes and their text values can be extracted. The two-dimensional area of closed polygons, as well as three-dimensional volumes of objects can be determined. By querying AutoCAD's objects, you can extract a wealth of information pertinent to your work, and you can query important data that AutoCAD creates automatically.

This chapter discusses the following topics:

Extracting Block and Attribute Data

Blocks and attribute object definitions contain a great deal of data. AutoCAD automatically creates some of the data, including data that defines the block, such as the block's name, its insertion coordinates, its insertion layer's name, its X,Y,Z scale factors, and its X,Y,Z extrusion direction. This wealth of information can easily be extracted into a text file.

Attribute data is user-defined. The data that AutoCAD extracts consists of one element, which is either a character string or a numeric value. The attribute value can be anything the user wants it to be, and the number of attributes that can be attached to a block is unlimited.

By choosing the particular data records of blocks and attributes you need, you can easily extract a wealth of important information from your drawing.

Using DDATTEXT/ATTEXT Commands

The commands used to extract block and attribute data have been around for several releases of AutoCAD and have not changed. The ATTEXT command, the command-line version, prompts you line-by-line for the information needed to extract data. The DDATTEXT is its dialog box counterpart, and is shown in figure 14.1. Both commands create an ASCII text file (by default, a TXT file) containing the extracted information.

Figure 14.1 The Attribute Extraction dialog box.


TIP: I use the DDATTEXT command to extract block and attribute data, preferring it simply because it is intuitive. To extract block and attribute data from script files or AutoLISP routines, however, I use the command-line version, ATTEXT, because script files and AutoLISP routines cannot pass information to a dialog box.

Either of these commands tell AutoCAD which block and attribute information to extract and how the extracted information will be arranged. The arrangement of the information is determined by a template file (discussed later in this chapter) and the file format you select, as discussed in the following section.

Extraction Formats

The first item AutoCAD requests via the Attribute Extraction dialog box or the ATTEXT command controls the extraction file format. The selected format determines the way each field within each record is separated and stored in the ASCII text file. AutoCAD provides three types of extraction file formats:

Figure 14.2 shows a drawing with several block insertions. Each insertion has three attributes. In the following three sections, the attribute data is extracted and the data is displayed in each format.

Figure 14.2 Inserted block objects, each with three attributes.


CDF File Format

The CDF file format writes one record for each block on a separate line. Each data value in a record is separated from the next by a comma, with text strings enclosed in apostrophes, as follows:

`Sewer','Manhole', 36
`Storm Drain','Manhole', 48
`Storm Drain','Manhole', 36
`Sewer','Manhole', 36
`Sewer','Manhole', 36
`Storm Drain','Manhole', 36
`Sewer','Manhole', 30
`Sewer','Manhole', 30

Notice that no spaces are between the fields separated by commas, with the exception of fields that contain numeric data. A single space precedes each number. If the number were negative, this space would be occupied by a minus sign. Note also that spaces are allowed in text strings enclosed in apostrophes.

SDF File Format

The SDF file format also writes one record for each block on a separate line; in this format, however, each data value in a record occupies a predefined field width. If the string or numeric value does not use the entire space allotted, AutoCAD fills the remainder of the field with spaces, as follows:

Sewer          Manhole      36
Storm Drain    Manhole      48
Storm Drain    Manhole      36
Sewer          Manhole      36
Sewer          Manhole      36
Storm Drain    Manhole      36
Sewer          Manhole      30
Sewer          Manhole      30

Note that no commas or apostrophes are used in this file format. Note also that the data values are aligned in easy-to-read columns. In each column, all string values are left-justified, and numeric values are right-justified.

DXF File Format

The DXF file format writes block data in AutoCAD's standard drawing interchange file format. An excerpt from a DXF file created with the DDATTEXT command follows:

  0
INSERT
  2
MANHOLE
 10
5.115973
 20
5.442408
 30
0.0
  0
ATTRIB
  1
Sewer
  2
OBJECT_CATEGORY
  0
ATTRIB
  1
Manhole
  2
OBJECT_TYPE
  0
ATTRIB
  1
36
  2
OBJECT_SIZE
  0
SEQEND
  0
EOF

This portion of the DXF output file is fragmented and represents attribute data from only one inserted block object. The entire DXF file created from the selected block insertions would fill about 30 pages of this book and be pretty boring to read. If you are familiar with DXF group codes, you may be able to decipher this fragment.

The CDF, SDF, and DXF file formats provide the capability for extracting block and attribute data into an ASCII text file. The CDF and SDF file formats are the most useful, enabling you to extract just the data you need, arranged in the order you want. The DXF file format, in contrast, is useful only when you need a copy of the DXF group code of the selected block objects.

Report Templates

To extract block and attribute data, the ATTEXT and DDATTEXT commands request the name of a template file. Template files are simple ASCII text files that list the data you want AutoCAD to extract. For example, a particular block may have 25 attributes attached to it. If you need only three, the template file would indicate which three to extract.

The following exercise demonstrates how to create a template file and then use it to write specific block and attribute data out to a text file in the CDF file format.


TIP: In the following exercise, I use the WordPad program, which comes with both Windows 95 and Windows NT. You can also use another text editor called NotePad, which automatically saves files as ASCII text files.

CREATING AND USING A TEMPLATE FILE TO EXTRACT BLOCK AND ATTRIBUTE DATA

1. Open the 14DWG01.DWG drawing file found on the accompanying CD-ROM.

The drawing opens, displaying several blocks. Each block represents a manhole, and also has attributes attached that uniquely describe it. For this exercise, you will extract each block's X,Y,Z insertion coordinates. You will also extract the attributes that indicate the block's diameter, and whether this is a sewer or storm drain manhole.

2. From the Start button on the Windows Taskbar, choose Programs, Accessories, WordPad. This opens WordPad.

3. In WordPad, enter the following lines, using spaces to align the columns:

BL:X N010004

BL:Y N010004

BL:Z N010004

OBJECT_CATEGORY C015000

OBJECT_SIZE N004000

In the previous step, the first column contains the field name. In the field name column, block data to be extracted begins with BL:, and is followed by the descriptor that indicates the data to extract. In this example, the block's X, Y, Z insertion coordinates are being extracted. Attribute data is extracted by specifying the attribute's tag in the field name column. In this example, the tag names are OBJECT_CATEGORY and OBJECT_SIZE, and were defined when the attribute was created.

The second column contains data that specifies whether the field will contain numeric or character values. This is discussed in detail later in the chapter.

4. In WordPad, choose File, Save. The Save As dialog box opens.

5. From the Save as type drop-down list, select Text Document, as shown in figure 14.3. This saves the file as an ASCII text file.

Figure 14.3 Choose Text Document to save the file in ACSII format.

6. Save the file in the ACADR14\SAMPLE directory and name it TEST01.TXT, as shown in figure 14.3.

7. Close WordPad.

Now that the template file is created, you will return to the AutoCAD drawing you already opened to extract its data.


WARNING: When you create a template file, it is important to ensure that the file is saved as an ASCII text file with the file extension .TXT. This is the file type and extension that AutoCAD looks for.

8. Return to AutoCAD and enter DDATTEXT at the Command: prompt. The Attribute Extraction dialog box opens.

9. In the File Format area, select Comma Delimited File (CDF).

10. Click on the Select Objects button, and then select the blocks individually. Start at the upper-left corner of the top row, and highlight across from left to right. Then continue with the bottom row, highlighting from left to right. After selecting all the blocks, press the Enter key to exit object selection and return to the Attribute Extraction dialog box.

11. Click on the Template File button, and open the TEST01.TXT file you saved in the ACADR14\SAMPLE directory.

The TEST01.TXT file name and its path appear in the text box, as shown in figure 14.4.

Figure 14.4 The Attribute Extraction dialog box.

12. Click on the Output File button and go to the ACADR14\SAMPLE directory. Then choose Save.

The 14DWG01.TXT file name and its path appear in the text box, as shown in figure 14.4.

13. Click on OK. AutoCAD creates the file and indicates that eight records exist in the extract file.

Next, you will open the 14DWG01.TXT extract file in WordPad and view it.


14. From the Start button on the Windows Taskbar, choose Programs, Accessories, WordPad.

15. Choose File, Open to display the Open dialog box.

16. From the Files of type drop-down list, select Text Documents (*.txt), as shown in figure 14.5.

Figure 14.5 The Open dialog box.

17. From the ACADR14\SAMPLE directory, open the 14DWG01.TXT extract file.

The extract file should contain the following data, in the order shown:

 67.8188, 111.6738, 0.0000,'Sewer', 30
 101.1619, 111.6738, 0.0000,'Sewer', 30
 134.0559, 111.6738, 0.0000,'Sewer', 36
 167.7358, 111.6738, 0.0000,'Sewer', 36
 203.8855, 111.6738, 0.0000,'Sewer', 36
 89.4862, 65.2266, 0.0000,'Storm Drain', 36
 129.5653, 65.2266, 0.0000,'Storm Drain', 36
 175.3699, 65.2266, 0.0000,'Storm Drain', 48

The first three fields represent the X,Y,Z insertion coordinates of the block insertions. The last two fields are extracted from the Object_Category and Object_Size attributes, respectively.

Controlling the CDF File Delimiters

The previous exercise created a Comma Delimited File (CDF). In this format, commas separate the fields and text strings are enclosed in apostrophes. Although this is very useful, commas and apostrophes might not be the delimiters you need. Fortunately, AutoCAD provides the capability to specify the characters used to delimit CDF files.

The C:DELIM template field indicates to AutoCAD which character to use as the field delimiter. The C:QUOTE template field indicates to AutoCAD which character to use to enclose text strings. Both of these template fields must be entered at the beginning of the template file.

For example, in the previous exercise, you could have indicated to AutoCAD that you wanted the extract file's fields separated by semicolons, with text strings enclosed in quotation marks. To do this, you would add the following lines to the template file:

C:DELIM           ;
C:QUOTE           "
BL:X              N010004
BL:Y              N010004
BL:Z              N010004
OBJECT_CATEGORY   C015000
OBJECT_SIZE       N004000


WARNING: To specify delimiters, you must specify characters that are not used as values in the fields; specifically, the field-delimiter character must not appear in the numeric field values. Therefore, 0-9 and periods must not be used to separate fields. Similarly, the text-string delimiter character must not appear in any of the text strings.

When you use this template file, it creates an extract file that contains the same information as before, but with the new delimiters, as follows:

 67.8188; 111.6738; 0.0000;"Sewer"; 30
 101.1619; 111.6738; 0.0000;"Sewer"; 30
 134.0559; 111.6738; 0.0000;"Sewer"; 36
 167.7358; 111.6738; 0.0000;"Sewer"; 36
 203.8855; 111.6738; 0.0000;"Sewer"; 36
 89.4862; 65.2266; 0.0000;"Storm Drain"; 36
 129.5653; 65.2266; 0.0000;"Storm Drain"; 36
 175.3699; 65.2266; 0.0000;"Storm Drain"; 48

Notice that the numeric and text string values are the same as before. The only difference is that the newly specified delimiters are used.


NOTE: AutoCAD automatically uses the comma and apostrophe as default delimiters. Therefore, it is not necessary to specify these values.

Specifying Field Width and Numeric Precision

In the previous template file examples, the second column contained one of two character sets, which looked like the following:

C015000

N004002

These two values indicate to AutoCAD the type of information the field value represents. The character set that begins with a C indicates a text string value, whereas the N indicates a numeric value. The next three characters tell AutoCAD the maximum field width. The last three characters indicate how many decimal places to use when extracting numeric values, which is 2 decimal places in the previous example. In the case of text strings, the last three characters have no meaning, but must be present and must be zero.


WARNING: Even though the last three characters are not used when extracting text strings, they must be present and set to 0.

Because you set these values in the template file, you need to know what type of data--numeric or text string--you are extracting, and its field length. You must then set these values accordingly. For example, if you are extracting a numeric value whose number is 1,000,000, and you want this number to be extracted to four decimal places, you would specify the following character set as a minimum:

N012004

This value tells AutoCAD that the field being extracted is a numeric field that will occupy a maximum of 12 spaces and have a decimal precision of 4. The number one million, carried out four decimal places (with no commas), looks like this:

1000000.0000

Notice that this number occupies 12 spaces. If the number were longer than 12 digits, it would be necessary to adjust the field length accordingly. Otherwise, AutoCAD would simply truncate the extracted value.

To show the effects of setting the numeric and text string character length too short, the template file from the previous exercise has been modified as follows:

C:DELIM           ;
C:QUOTE           "
BL:X              N002001
BL:Y              N002001
BL:Z              N002001
OBJECT_CATEGORY   C005000
OBJECT_SIZE       N001000

Notice that the field width values and decimal place values are too short to extract the block and attribute values correctly. When this template is applied to the previous drawing file, the extract file results are as follows:

67;11;0.;"Sewer";3
10;11;0.;"Sewer";3
13;11;0.;"Sewer";3
16;11;0.;"Sewer";3
20;11;0.;"Sewer";3
89;65;0.;"Storm";3
12;65;0.;"Storm";3
17;65;0.;"Storm";4

As you can see, even though the extract file used the same set of blocks, the data extracted does not correctly represent the true values of the blocks and attributes in the drawing.

Additionally, when DDATTEXT or ATTEXT was executed with the modified template file, it issued the following warnings when extracting the data:

** Field overflow in record 1
** Field overflow in record 2
** Field overflow in record 3
** Field overflow in record 4
** Field overflow in record 5
** Field overflow in record 6
** Field overflow in record 7
** Field overflow in record 8
8 records in extract file.

As demonstrated, it is important that you know in advance what type of data you are extracting, and the field widths necessary to obtain the true value of the block or attribute.

Extraction Data Types

The tag name is the only available extraction data type defined for attributes. Blocks, on the other hand, have a variety of data that can be extracted. To extract each type of block data, you must enter the appropriate field type in the template file. Each block data type begins with BL: and is followed by the character set that specifies the type of block data to be extracted. The following is a list of the various block data types, their definitions, and an example of each. To provide an example of each of the block extraction data types, the data types were added to the template used in the last exercise, and then the data was extracted.

	 			 1; 67.8188; 111.6738; 0.0000;"Sewer"; 30
				 1; 101.1619; 111.6738; 0.0000;"Sewer"; 30
				 1; 134.0559; 111.6738; 0.0000;"Sewer"; 36
				 1; 167.7358; 111.6738; 0.0000;"Sewer"; 36
				 1; 203.8855; 111.6738; 0.0000;"Sewer"; 36
 				 1; 89.4862; 65.2266; 0.0000;"Storm Drain"; 36
 				 1; 129.5653; 65.2266; 0.0000;"Storm Drain"; 36
 				 1; 175.3699; 65.2266; 0.0000;"Storm Drain"; 48
2; 135.2779; 87.4341; 0.0000;"Sewer"; 30
		"MANHOLE"; 67.8188; 111.6738; 0.0000;"Sewer"; 30
		"MANHOLE"; 101.1619; 111.6738; 0.0000;"Sewer"; 30
		"MANHOLE"; 134.0559; 111.6738; 0.0000;"Sewer"; 36
		"MANHOLE"; 167.7358; 111.6738; 0.0000;"Sewer"; 36
		"MANHOLE"; 203.8855; 111.6738; 0.0000;"Sewer"; 36
		"MANHOLE"; 89.4862; 65.2266; 0.0000;"Storm Drain"; 36
		"MANHOLE"; 129.5653; 65.2266; 0.0000;"Storm Drain"; 36
		"MANHOLE"; 175.3699; 65.2266; 0.0000;"Storm Drain"; 48
		1; 67.8188; 111.6738; 0.0000;"Sewer"; 30
		2; 101.1619; 111.6738; 0.0000;"Sewer"; 30
		3; 134.0559; 111.6738; 0.0000;"Sewer"; 36
		4; 167.7358; 111.6738; 0.0000;"Sewer"; 36
 		5; 203.8855; 111.6738; 0.0000;"Sewer"; 36
 		6; 89.4862; 65.2266; 0.0000;"Storm Drain"; 36
 		7; 129.5653; 65.2266; 0.0000;"Storm Drain"; 36
		8; 175.3699; 65.2266; 0.0000;"Storm Drain"; 48
		"2B"; 67.8188; 111.6738; 0.0000;"Sewer"; 30
		"30"; 101.1619; 111.6738; 0.0000;"Sewer"; 30
		"3"; 134.0559; 111.6738; 0.0000;"Sewer"; 36
		"1C"; 167.7358; 111.6738; 0.0000;"Sewer"; 36
		"21"; 203.8855; 111.6738; 0.0000;"Sewer"; 36
		"26"; 89.4862; 65.2266; 0.0000;"Storm Drain"; 36
		"17"; 129.5653; 65.2266; 0.0000;"Storm Drain"; 36
		"12"; 175.3699; 65.2266; 0.0000;"Storm Drain"; 48
		"LAYER1"; 67.8188; 111.6738; 0.0000;"Sewer"; 30
		"LAYER1"; 101.1619; 111.6738; 0.0000;"Sewer"; 30
		"LAYER2"; 134.0559; 111.6738; 0.0000;"Sewer"; 36
		"LAYER2"; 167.7358; 111.6738; 0.0000;"Sewer"; 36
		"LAYER2"; 203.8855; 111.6738; 0.0000;"Sewer"; 36
		"LAYER3"; 89.4862; 65.2266; 0.0000;"Storm Drain"; 36
		"LAYER3"; 129.5653; 65.2266; 0.0000;"Storm Drain"; 36
		"LAYER4"; 175.3699; 65.2266; 0.0000;"Storm Drain"; 48
 		0.000000; 67.8188; 111.6738; 0.0000;"Sewer"; 30
 		0.000000; 101.1619; 111.6738; 0.0000;"Sewer"; 30
 		0.000000; 134.0559; 111.6738; 0.0000;"Sewer"; 36
 		0.000000; 167.7358; 111.6738; 0.0000;"Sewer"; 36
 		0.000000; 203.8855; 111.6738; 0.0000;"Sewer"; 36
 		0.000000; 89.4862; 65.2266; 0.0000;"Storm Drain"; 36
 		0.000000; 129.5653; 65.2266; 0.0000;"Storm Drain"; 36
 		0.000000; 175.3699; 65.2266; 0.0000;"Storm Drain"; 48
		10.0; 10.0; 10.0; 67.8188; 111.6738; 0.0000;"Sewer"; 30
		10.0; 10.0; 10.0; 101.1619; 111.6738; 0.0000;"Sewer"; 30
		10.0; 10.0; 10.0; 134.0559; 111.6738; 0.0000;"Sewer"; 36
		10.0; 10.0; 10.0; 167.7358; 111.6738; 0.0000;"Sewer"; 36
		10.0; 10.0; 10.0; 203.8855; 111.6738; 0.0000;"Sewer"; 36
 		10.0; 10.0; 10.0; 89.4862; 65.2266; 0.0000;"Storm Drain"; 36
		10.0; 10.0; 10.0; 129.5653; 65.2266; 0.0000;"Storm 				¬Drain"; 36
		10.0; 10.0; 10.0; 175.3699; 65.2266; 0.0000;"Storm 				¬Drain"; 48
		0.0; 0.0; 1.0; 67.8188; 111.6738; 0.0000;"Sewer"; 30
 		0.0; 0.0; 1.0; 101.1619; 111.6738; 0.0000;"Sewer"; 30
 		0.0; 0.0; 1.0; 134.0559; 111.6738; 0.0000;"Sewer"; 36
 		0.0; 0.0; 1.0; 167.7358; 111.6738; 0.0000;"Sewer"; 36
 		0.0; 0.0; 1.0; 203.8855; 111.6738; 0.0000;"Sewer"; 36
 		0.0; 0.0; 1.0; 89.4862; 65.2266; 0.0000;"Storm Drain"; 36
 		0.0; 0.0; 1.0; 129.5653; 65.2266; 0.0000;"Storm Drain"; 36
 		0.0; 0.0; 1.0; 175.3699; 65.2266; 0.0000;"Storm Drain"; 	48

Table 14.1 Extraction Data Types

Block Data Type Definition
BL:Level Level of block nesting
BL: Name Block's name
BL:X/BL:Y/BL:Z Block's insertion coordinates
BL:NUMBER Current extracted block's number
BL:HANDLE Block's handle value
BL:LAYER Block's insertion layer value
BL:ORIENT Block's rotation angle
BL:XSCALE/BL:YSCALE/BL:ZSCALE Block's X,Y,and Z scale factor
BL:XEXTRUDE/BL:YEXTRUDE/ X,Y, and Z extrusion (3D
BL:ZEXTRUD orientation)

In this section, you have learned how to extract block and attribute data. In the next section, you learn about extracting other object data.

Obtaining Object Information

The capability to query for object and drawing data is a valuable feature of AutoCAD. With Release 14, querying tools are conveniently grouped together for easy, intuitive access. Additionally, the Object Properties toolbar has been enhanced to make identifying the most common properties of an object as easy as selecting the object itself.

Object Properties Toolbar

With Release 14, AutoCAD's Object Properties toolbar automatically displays the selected object's layer, color, and linetype properties. As additional objects are selected, only properties that are the same for all selected objects are listed. When the selected objects have different properties, such as different layers, the property value is left blank.

The following exercise demonstrates the querying capabilities of AutoCAD's enhanced Object Properties toolbar.

QUERYING OBJECTS WITH THE OBJECT PROPERTIES TOOLBAR

1. Open the 14DWG02.DWG drawing file found on the accompanying CD-ROM. The drawing opens and is displayed. Notice that the Object Properties toolbar lists the layer 0, the color Bylayer, and the linetype Bylayer. This represents AutoCAD's current object-creation mode. If an object were created now, it would be assigned the layer 0 and the color and the linetype of Bylayer.

2. Choose the dashed contour line (the sixth line from the top).

AutoCAD displays grips along the polyline (see fig. 14.6). Notice that the properties displayed in the Object Properties toolbar now reflect the properties of the selected object.

Figure 14.6 The current object's properties are displayed in the Object Properties toolbar.

3. Choose the dashed contour line above the one you just chose. AutoCAD displays grips along the polyline (see fig. 14.7). Notice that AutoCAD no longer displays any properties in the Object Properties toolbar. This occurs because the two objects reside on different layers, and have different color and linetype settings.

Figure 14.7 No properties are displayed in the Object Properties toolbar when the two objects have no common properties.

4. Hold down the Shift key, and click twice on the dashed line you originally selected. Make sure you don't select the contour line on a grip--this makes the grip warm instead of deselecting the line.

AutoCAD deselects the contour line and removes the grips (see fig. 14.8). Because only one object is currently selected, the properties of the object are displayed in the Object Properties toolbar.


TIPP: I frequently use the DDMODIFY command to list an object's properties. The advantage of using this command is that many of the object's properties are listed and can be edited if necessary. To start the command, choose Modify, Properties.

Figure 14.8 The Object Properties toolbar displays the current object's properties when it is the only object selected.

Inquiry Tools

In Release 14, the querying tools are conveniently grouped together in a single location. When you choose Tools, Inquiry, AutoCAD displays all its querying tools (see fig. 14.9). To access one of the tools, simply click on it.

Figure 14.9 Accessing the querying tools from the Inquiry fly-out menu on the Tools pull-down menu.

Distance

The DIST command is used to measure the distance between two points in an AutoCAD drawing. When you use the DIST command to query lengths, it's important to realize that this command measures distances three-dimensionally. If you pick two points that are not on the same plane, the overall distance will be based on a 3D vector. Even when you are using Object Snaps, if the objects are not on the same plane, the distance provided will be based on a 3D vector. To ensure that the distance is based on the current two-dimensional UCS, use X,Y,Z point filters when you query distance from 3D objects.

The following exercise demonstrates how to use X,Y,Z point filters to measure a distance two-dimensionally.

MEASURING DISTANCES WITH X,Y,Z POINT FILTERS

1. Continue with the 14DWG02.DWG drawing file from the previous exercise.

2. Press the Esc key twice to clear the grips.

3. From the Tools menu, choose Inquiry, Distance.

4. Using endpoint snaps, snap to the left end of the top blue contour. Then snap to the left end of the blue line below it. AutoCAD displays the following data:

Distance = 3767.7248, Angle in XY Plane = 270,  Angle from XY Plane = 2, Delta X = 0.0000,  Delta Y = -3766.3975, Delta Z = 100.0000


NOTE: Notice that AutoCAD indicates that the Angle from XY Plane = 2. This angle is measured up from the XY plane in the Z direction. This data tells you that the distance is a 3D vector, caused by the two contours not being on the same XY plane. The first contour has an elevation of 100; the second, an elevation of 200.
Next, you snap to the same two points while using X,Y,Z point filters.

5. From the Tools menu, choose Inquiry, Distance.

6. Enter .XY (the period in front of the XY is necessary).

7. Using endpoint snaps, snap to the left end of the top blue contour.

8. Enter 0 when prompted for the Z value.

9. When AutoCAD prompts for the second point, enter .XY again.

10. Snap to the left end of the blue line below the top blue line.

11. Enter 0 when prompted for the Z value. AutoCAD displays the following data:

Distance = 3766.3975, Angle in XY Plane = 270,  Angle from XY Plane = 0, Delta X = 0.0000,  Delta Y = -3766.3975, Delta Z = 0.0000

Notice that the measured distance is slightly smaller than the first distance you measured. This is the result of using the X,Y,Z point filters and setting the Z value to 0. This distance represents the true horizontal distance.


NOTE: The last distance queried by using the DIST command is saved as a system variable. To view it, type DISTANCE at the Command: prompt.

Querying for Areas in Blocks and Xrefs

The AREA command is useful for finding the area of many AutoCAD objects. AutoCAD can find the area of circles, ellipses, splines, regions, closed polylines, or polygon objects. It also quickly finds the length of an open polyline. Using the AREA command's Object option, AutoCAD calculates and lists the object's area and perimeter length.


WARNING: The AREA command provides both the total length and the total area of an open polyline object. Although the length is accurate, the calculated area is not.

If you select an object that is inserted as a block or xref, however, AutoCAD warns that the selected object does not have an area. How can you calculate the area of objects inserted as blocks or xrefs?

The area of objects inserted as blocks or xrefs can be queried by using the BOUNDARY command. With this command, AutoCAD creates region objects that provide the area and perimeter of block and xref objects.

The next exercise demonstrates how to calculate the area of objects contained within blocks or xrefs.

DETERMINING THE AREA OF XREF OBJECTS

1. Open the 14DWG03b.DWG drawing file found on the accompanying CD-ROM. The drawing opens and displays four objects. The three dashed objects are part of an xref. The rectangle object is part of the current drawing.

Next, you calculate the areas of the xref objects.

2. From the Draw menu, choose Boundary. The Boundary Creation dialog box appears.

3. From the Object Type drop-down list, select Region.

4. Click on the Pick Points button.

5. Pick inside the smaller circle that lies inside the octagon. AutoCAD determines the boundary from the circle object and highlights it.

6. Continue selecting the interior of the remaining xref objects. Pick inside the octagon, but outside the contained circle. Pick the area shared by the octagon and the left circle. Finally, pick inside the left circle, but outside the octagon. When you finish picking inside the xref objects, all objects are highlighted (see fig. 14.10).

7. Press Enter to end object selection.

Figure 14.10 The xref objects are highlighted.



NOTE:
AutoCAD notes that the BOUNDARY command created five regions. It created two regions for the circle inside the octagon: one because you picked inside the circle, and the second because you picked inside the octagon but outside the circle. This occurs because Island Detection was enabled in the Boundary Creation dialog box.

After you create the region objects, you can use the AREA command to calculate their area and perimeter. You can also create a single composite region object of the four objects, and calculate its area. This is accomplished by using Boolean operations, as follows:


8. From the Modify menu, choose Boolean, Union.

9 When prompted to select objects, enter F. This begins the fence selection method.

10. Select all the region objects except the circle inside the octagon by picking inside the octagon as shown in figure 14.11.

11. Drag the fence line left and pick inside the circle as shown in figure 14.11.

12. Press Enter when you have finished, and then Redraw the screen.

Figure 14.11 The FENCE selection method is used to select the region objects.


AutoCAD creates a new composite region made up of the three smaller regions, and then it erases the three smaller regions. You can calculate the new region's area and perimeter using the AREA command.

Next, you subtract the remaining circle region from the composite region. 13. From the Modify menu, choose Boolean, Subtract. AutoCAD prompts you to select the objects from which to subtract regions.

14. Choose the composite region, and press Enter.

Next, AutoCAD prompts you to select the regions to subtract.


15. Use the Fence selection method to choose the small circle region, and press Enter. AutoCAD subtracts the circle region from the composite region, creating a new composite region, shown highlighted in figure 14.12.

Next, you use the AREA command to calculate the area and perimeter of the composite region.

16. From the Tools menu, choose Inquiry, AREA.

17. When prompted, enter O for Object, and then choose the composite region.

AutoCAD calculates the region's area and displays it as follows:

Area = 405708.1915, Length = 4060.4512

Figure 14.12 The highlighted composite region.

By using this technique, you can quickly determine the area and perimeter of inserted block and xref objects.

Querying with AutoLISP

Two commands, LIST and DBLIST, display object data. The LIST command displays the object data of selected objects. The DBLIST command displays the object data of all objects in the drawing. Both commands are useful for showing information about objects, such as object type, layer, color, linetype, pertinent coordinate values, and in some cases, area and overall length.

Unfortunately, when these commands are used to display object data of a block or xref, only the block's data is shown, not all the objects that make up the block. Although this may be satisfactory in some situations, times may occur when you need more data. For example, how do you find the layer on which an object resides when that object is part of a block or xref?

You can extract data from objects within a block insertion by using a few AutoLISP functions. AutoLISP functions are entered at the Command: prompt, and display an object's data in DXF group code formats.

The next exercise uses the following AutoLISP functions to extract object data:


NOTE: With Release 13, AutoCAD changed the name of entities to objects. Some AutoLISP function names still refer to an object as an entity, however.

QUERYING AN INSERT OBJECT'S DATA WITH AUTOLISP

1. Open the 14DWG03c.DWG drawing file found on the accompanying CD-ROM. The drawing displays the four objects from the previous exercise.

First, you use the entsel function to extract data from the insert object.


2. At the Command: prompt, enter the following, including the parentheses:

(entsel)

3. When prompted, choose the octagon object. AutoCAD displays the following data:

(<Entity name: 1fc0578> (795.9 868.052 0.0))


NOTE: The data represents a list of two items that AutoCAD returned. The first item, <Entity name: 1fc0578>, is the selected object's name. The object name you see may be different. The second item is the X,Y,Z pick point coordinates used to select the entity. The pick points in this example are probably slightly different from yours because it is unlikely that you selected the object at the exact same spot.

The object's name is a unique identifier for objects in this drawing. AutoCAD assigns each object this unique identifier when the drawing is loaded (the identifier you see may be different). It represents the object (or entity) name of the insert object. No other object in this drawing has the same name.
Next, use the nentsel function to extract data.


4. At the Command: prompt, enter the following, including the parentheses:

(nentsel)

5. When prompted, choose the octagon object. This time, AutoCAD displays different data information, as follows:

(<Entity name: 2050518> (956.579 284.152 0.0) ((1.0 0.0 0.0) 
(0.0 1.0 0.0) (0.0 0.0 1.0) (0.0 0.0 0.0))
(<Entity name: 1fc0578>))


NOTE: Notice that the object (entity) has two names. The last name is the same as the name returned by the entsel function. The first name, however, is different. This list of data represents the values of the object nested inside the insert object. The first name is the octagon's object name. The second name simply indicates the object name of the octagon's parent object. In this case, the parent object is an xref insert object.

To return the data list of the octagon object, you need to use the entget function. This function expects an object's name to be passed to it--this is where the car function is used.

Next, the car and nentsel functions are used to return the octagon object's name.


6. At the Command: prompt, enter the following, including the parentheses:

(car (nentsel))

7. When prompted, choose the octagon object. This time, AutoCAD returns only the object's name:

<Entity name: 2050518>

The car function returned the first item in the list, which was returned by nentsel; in this case, it is the octagon object's name. This is the name the entget function needs to use to return the object's data list.


8. At the Command: prompt, enter the following, including the parentheses:

(entget (car (nentsel)))

9. When prompted, choose the octagon object. This time, AutoCAD returns the octagon object's data list, as follows:

((-1 . <Entity name: 2050518>) (0 . "LWPOLYLINE") (5 . "23")
(100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbPolyline")
(90 . 8) (70 . 1) (43 . 0.0) (38 . 0.0) (39 . 0.0)
(10 1375.09 610.235)(40 . 0.0) (41 . 0.0) (42 . 0.0)
(10 1271.84 859.5) (40 . 0.0) (41 . 0.0) (42 . 0.0)
(10 1022.57 962.749) (40 . 0.0) (41 . 0.0) (42 . 0.0)
(10 773.308 859.5) (40 . 0.0) (41 . 0.0) (42 . 0.0)
(10 670.059 610.235) (40 . 0.0) (41 . 0.0) (42 . 0.0)
(10 773.308 360.97) (40 . 0.0) (41 . 0.0) (42 . 0.0)
(10 1022.57 257.721) (40 . 0.0) (41 . 0.0) (42 . 0.0)
(10 1271.84 360.97) (40 . 0.0) (41 . 0.0) (42 . 0.0)
(210 0.0 0.0 1.0))

Notice that the list consists of data grouped together by parentheses. Each group enclosed in a set of parentheses is called a data pair. The first number in each group is an integer that indicates the type of data the remaining values represent. For example, the integer 10 indicates a coordinate value, and groups that start with a 10 represent a coordinate. A 0 indicates the type of object; in this case, a lightweight polyline. The object's layer is indicated by the integer 8.

The values listed represent the actual data values of the octagon object, which resides in an xref. Notice that the octagon is shown as residing on the layer 0, even though the xref was inserted on layer Xref. This is because it resides on the layer 0 of the xref drawing.


NOTE: For a complete list of group codes, look in the AutoCAD documentation under "DXF Group Codes."

Summary

In this chapter, you learned about querying for different types of AutoCAD objects. You learned about using the DDATTEXT command for block and attribute extraction, and about the different extraction formats. You found out how to create report templates, and how to control CDF file delimiters for block data extraction. This chapter showed you how to specify field width and numeric precision, and told you about the different data extraction types for blocks and attributes. You also learned how to quickly query for object data from the Object Properties toolbar, and how to query properly for 2D distances, areas in blocks and xrefs, and how to use AutoLISP to extract an object data list.

Quickly querying objects for data that AutoCAD automatically creates, such as layer, color, and linetype, increases your productivity by providing information you frequently need during an editing session. By querying data that users assign, such as attribute data, you can increase your productivity by automatically extracting large amounts of information you need to complete your work, as when you need to create a bill of materials.


Previous chapterNext chapterContents

© Copyright, Macmillan Computer Publishing. All rights reserved.